// pages/credentials/credentialsDetail/credentialsDetail.js
import {
  getCertificate
} from '../../../api/certificate.js';
Page({

  /**
   * 页面的初始数据
   */
  data: {
    id: 0, // 证书id
    isMine: false,
    imgList: [],
    intro: {},
    tagStyle: {
      p: 'line-height:24px;font-size:16px;color:#666666;letter-spacing:1px;margin-bottom:15rpx;',
      img: 'width:100vw;height:auto;',
    }
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.data.id = Number(options.id);
    this.setData({
      isMine: options.isMine === '1',
    })
    this.loadCertificate();
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onShow: function () {
    this.setData({
      'intro.status': this.data.intro.status || 0,
    })
  },

  /**
   * 加载证书详情
   */
  loadCertificate() {
    getCertificate(this.data.id).then(res => {
      this.setData({
        intro: res,
        imgList: res.image.split(','),
      })
    })
  },

  /**
   * 证书报名跳转
   */
  credentialsEnroll() {
    if (this.data.intro.status === -1) {
      wx.navigateTo({
        url: '/pages/credentials/enroll/enroll?id=' + this.data.id,
      })
    } else {
      wx.navigateTo({
        url: '/pages/credentials/user/user',
      })
    }
  },

  preview(event) {
    console.log(this.data.imgList)
    let currentUrl = event.currentTarget.dataset.src
    wx.previewImage({
      current: currentUrl, // 当前显示图片的http链接
      urls: this.data.imgList // 需要预览的图片http链接列表
    })
  }
})